#ifndef QHOSTFACTORY_H
#define QHOSTFACTORY_H

#include "objects_global.h"

#include <QMetaObject>
#include <QMap>
#include <QString>

#define CONTAINNERS_INDEX   0
#define BUTTON_INDEX        1000
#define INPUT_INDEX         2000
#define DISPLAY_INDEX       3000
#define EXTENSION_INDEX     4000
#define BASE_GRAPHICS_INDEX 5000
#define CUSTOM_INDEX        20000


class QAbstractHost;
class XMLObject;

struct tagHostInfo
{
    const QMetaObject *m_host_object;
    QString         m_name;
    QString         m_show_icon;
    QString         m_show_group;
    QString         m_show_name;
    QString         m_type;
    int             m_index;
};

class OBJECTS_SHARED_EXPORT QHostFactory
{
public:
    QHostFactory(const QString name,
                 const QString& type,
                 const QString& show_icon,
                 const QString& show_name,
                 const QString& show_group,
                 const QMetaObject* host,
                 int index);
public:
    static void register_host(const QString name,
                              const QString& type,
                              const QString& show_icon,
                              const QString& show_name,
                              const QString& show_group,
                              const QMetaObject* host,
                              int index);
    static QAbstractHost* create_host(const QString& name);
    static QAbstractHost* create_host(XMLObject* xml);
    static QList<tagHostInfo*> get_host_info();
    static tagHostInfo *  get_host_info(const QString &name);

    static void         sort();
};


#ifndef qRegisterHost
#define qRegisterHost(name,class_name,index) QHostFactory factory_##class_name(\
                                                    name,\
                                                    class_name::get_object_type(),\
                                                    class_name::get_show_icon(),\
                                                    class_name::get_show_name(),\
                                                    class_name::get_show_group(),\
                                                    &class_name::staticMetaObject,\
                                                    index);
#endif

#endif // QHOSTFACTORY_H
